﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">任务名称</div>
                    <div class="formcontent">
                        <input name="TaskName" type="text" class="form-control required" placeholder="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle required">任务类别</div>
                    <div class="formcontent">
                        <select class="form-control required" id="TaskType" name="TaskType" onchange="TaskTypeChange()">
                            <option value="100" selected="selected">循环任务</option>
                            <option value="200">定时任务</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="formrow" id="CycleSetting">
                <div class="col-xs-6">
                    <div class="formtitle required">执行间隔</div>
                    <div class="formcontent">
                        <input name="TaskExecutePeriod" id="TaskExecutePeriod" type="number" class="form-control required" placeholder="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle required">间隔单位</div>
                    <div class="formcontent">
                        <select class="form-control required" name="TaskExecuteUnit" id="TaskExecuteUnit">
                            <option value="100" selected="selected">秒</option>
                            <option value="200">分</option>
                            <option value="300">时</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="formrow" style="display:none" id="CORNSetting">
                <div class="col-xs-12">
                    <div class="formtitle required">CORN表达式</div>
                    <div class="formcontent">
                        <input name="CornExplain" id="CornExplain" type="text" class="form-control" placeholder="">
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">Job执行类</div>
                    <div class="formcontent">
                        <input name="JobClassName" type="text" class="form-control required" placeholder="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle required">任务标识</div>
                    <div class="formcontent">
                        <input name="TaskTag" type="text" class="form-control required" placeholder="">
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">任务状态</div>
                    <div class="formcontent">
                        <label class="radio-inline">
                            <input type="radio" name="TaskStatus" checked value="100">停止
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="TaskStatus" value="200">运行
                        </label>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle">排序</div>
                    <div class="formcontent">
                        <input name="SortNum" type="text" class="form-control" placeholder="" value="0">
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-12">
                    <div class="formtitle">备注</div>
                    <div class="formcontent">
                        <textarea name="TaskInfo" class="form-control" rows="3" placeholder=""></textarea>
                    </div>
                </div>
            </div>
            <div style="display:none">
                <input name="TaskGuid" type="text" class="form-control" placeholder="">
            </div>
            <div class="formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()"><span class="btntext">保 存</span></button>
                <button class="btn cloudbtn" type="button" onclick="Close()"><span class="btntext">关 闭</span></button>
            </div>
        </form>
    </div>
    <script>
        var validator = $("#form").validate();
        $(function () {
            LoadDetail();
        })
        function LoadDetail() {
            var param = { "TaskGuid": GetUrlParam("TaskGuid") }
            CloudPost(param, "opdetail", function (res) {
                if (res.code == 0) {
                    $("#form").SetForm(res.data);
                    TaskTypeChange();
                }
            })
        }
        function Save() {
            if (validator.form()) {
                var param = $("#form").GetForm();
                CloudPost(param, "opupdate", function (res) {
                    if (res.code == 0) {
                        OpenSuccess("保存成功！", function () {
                            CloseDialog();
                        })
                    } else {
                        OpenFail(res.data)
                    }
                })
            }
        }
        function Close() {
            CloseDialog();
        }

        function TaskTypeChange() {
            var TaskType = $('#TaskType option:selected').val();
            if (TaskType == "100") {
                $("#CycleSetting").show();
                $("#CORNSetting").hide();
                $("#CornExplain").removeClass("required");
                $("#TaskExecutePeriod").addClass("required");
                $("#TaskExecuteUnit").addClass("required");
            } else {
                $("#CycleSetting").hide();
                $("#CORNSetting").show();
                $("#CornExplain").addClass("required");
                $("#TaskExecutePeriod").removeClass("required");
                $("#TaskExecuteUnit").removeClass("required");
            }
        }
    </script>
</body>
</html>
